package 结构型模式.外观;

/**
 * @ClassNameAppearanceTest
 * @Description
 * @Author
 * @Date2021/12/20 16:07
 **/
public class AppearanceTest {
    public static void main(String[] args) {
        // 客户端调用
        Appearance appearance = new Appearance();
        appearance.buy(new Goods("洗发水"));
    }
}

class Goods {
    private String name;

    public Goods(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

// 仓库系统
class WarehouseSystem {
    public boolean isStock(Goods goods) {
        System.out.println(goods.getName() + "有库存");
        return true;
    }
}

// 支付系统
class PaySystem {
    public boolean pay(Goods goods) {
        System.out.println("支付" + goods.getName() + "成功");
        return true;
    }
}

// 物流系统
class LogisticsSystem {
    public void deliver(Goods goods) {
        System.out.println(goods.getName() + "发货成功");
    }
}

// 外观模式类
class Appearance {
    public void buy(Goods goods) {
        WarehouseSystem warehouseSystem = new WarehouseSystem();
        boolean stock = warehouseSystem.isStock(goods);
        // 判断是否有库存
        if (stock) {
            PaySystem paySystem = new PaySystem();
            boolean pay = paySystem.pay(goods);
            // 判断是否支付成功
            if (pay) {
                LogisticsSystem logisticsSystem = new LogisticsSystem();
                logisticsSystem.deliver(goods);
            }
        }


    }
}
